Imports System.Transactions
Imports KanBan.Pgd.Common
Imports KanBan.Pgd.Domain.Entities
Imports NUnit.Framework
Imports KanBan.Pgd.Infrastructure
Imports KanBan.Pgd.Infrastructure.Repositories
Imports KanBan.Pgd.Domain.ValueObjects

<TestFixture()> _
Public Class BusinessTest

    Private scope As TransactionScope = Nothing

    <SetUp()> _
    Public Sub Init()
        scope = New TransactionScope()
    End Sub

    <TearDown()> _
    Public Sub Dispose()
        If Not scope Is Nothing Then
            scope.Dispose()
            scope = Nothing
        End If
    End Sub

    <Test()> _
    Public Sub SaveNewSearchRequestTest()

        Dim searchRequestRepository As New SearchRequestRepository()
        Dim userRepository As New UserRepository()
        Dim profileRepository As New ProfileRepository()


        Dim user As User = userRepository.GetById(TestConstants.AreaManager1UserId)
        Dim profile As Profile = profileRepository.GetById(TestConstants.TestProfileId)
        Dim profileLevel As ProfileLevel = ValueObjectRepository(Of ProfileLevel).GetById(TestConstants.SeniorLevelId)
        Dim priority As Priority = ValueObjectRepository(Of Priority).GetById(TestConstants.MediumPriorityId)

        Dim searchRequest As New SearchRequest(TestConstants.TestSku, _
                                               user, _
                                               profile, _
                                               profileLevel, _
                                               priority)

        Dim request As SearchRequest = searchRequestRepository.SaveOrUpdate(searchRequest)

        Assert.IsNotNull(request)
        Assert.AreEqual(TestConstants.AreaManager1UserId, request.Requester.Id)
        Assert.AreEqual(TestConstants.TestProfileName, request.SearchedProfile.Name)
        Assert.AreEqual(TestConstants.SeniorLevelName, request.SearchedProfileLevel.Name)
        Assert.AreEqual(TestConstants.MediumPriorityName, request.Priority.Name)
                                                            
    End Sub

    <Test()> _
    Public Sub SaveNewArea()

        Dim areaRepository As New AreaRepository()

        Dim area As New Area(TestConstants.TestAreaId, TestConstants.TestAreaName)

        Dim retrievedArea As Area = areaRepository.SaveOrUpdate(area)

        Assert.IsNotNull(retrievedArea)
        Assert.AreEqual(TestConstants.TestAreaName, retrievedArea.Name)

    End Sub


End Class
